/*
 * Copyright (c) 2023, 2024,yzc.cn All rights reserved.
 *
 */
package cn.yzc.write;

import cn.yzc.pojo.Student;
import cn.yzc.utils.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.ListUtils;

import java.util.Date;
import java.util.List;

/**
 * <p>Project: EasyExcel - SimpleWrite</p>
 * <p>Powered by yzc On 2024-03-20 15:43:42</p>
 * <p>描述：<p>
 *
 * @author yzc [youzhicheng0415@163.com]
 * @version 1.0
 * @since 17
 */
public class SimpleWrite {
    /**
     * 准备测试的数据
     * @param count
     * @return
     */
   private static List<Student> data(int count){
       List<Student> list = ListUtils.newArrayList();
       for (int i = 1; i <= count; i++) {
           String gender = (i%2 == 0)?"女":"男";
           list.add(new Student(i,"学生"+i,gender,new Date()));
       }
       return list;
   }

    /**
     * 快速入门写数据
     */
    public static void main(String[] args) {
        String fileName = TestFileUtil.getPath() + "simpleWrite" + System.currentTimeMillis() + ".xlsx";
        // 这里 需要指定写用哪个class去写，然后写到第一个sheet，名字为模板 然后文件流会自动关闭
        // 如果这里想使用03 则 传入excelType参数即可
        EasyExcel.write(fileName, Student.class).sheet("模板").doWrite(data(10));

    }



}
